package com.itheima.myhashsettest;

import java.util.Objects;

public class HashSetDemo2 {
    public static void main(String[] args) {
        Person p1 = new Person("zs",21);
        Person p2 = new Person("zs",22);

        System.out.println(p1.hashCode());//23934342    121789
        p1.setAge(22);
        System.out.println(p1.hashCode());//23934342    121790
        System.out.println(p2.hashCode());//22307196    121790
    }
}

class Person{
    private String name;
    private int age;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age &&
                Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Person() {
    }
}